<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "chat_session".
 *
 * @property integer $id
 * @property string $sender
 * @property string $receiver
 * @property string $sender_name
 * @property string $receiver_name
 * @property integer $message_number
 * @property integer $update_time
 * @property integer $state
 */
class ChatSession extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'chat_session';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['sender', 'receiver', 'sender_name', 'receiver_name', 'update_time'], 'required'],
            [['message_number', 'update_time', 'state'], 'integer'],
            [['sender', 'receiver', 'sender_name', 'receiver_name'], 'string', 'max' => 32],
            [['sender', 'receiver'], 'unique', 'targetAttribute' => ['sender', 'receiver'], 'message' => 'The combination of Sender and Receiver has already been taken.'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'sender' => 'Sender',
            'receiver' => 'Receiver',
            'sender_name' => 'Sender Name',
            'receiver_name' => 'Receiver Name',
            'message_number' => 'Message Number',
            'update_time' => 'Update Time',
            'state' => 'State',
        ];
    }
    
    
    public function getSession($condition){
        $result = (new \yii\db\Query())
                ->select('*')
                ->from('chat_session')
                ->where($condition)
                ->all();
        return $result;
    }
}
